import { message, Button } from 'antd';

export default {
  namespace: 'home',
  state: {
    kpiCount: {
      totalCount: 1,
      totalCompleteCount: 2,
    },
    kpiMoney: {
      totalCount: 3,
      totalCompleteCount: 4,
    },
    KpiIncrement: {},
    staticCount: {},
    notification: [],
    lawList: [],
    unDoList: [],
    excelList: [],
  },
  reducers: {
    save(state, { payload }) {
      let newValue = Object.assign({}, state, payload);
      return newValue;
    },
  },
  effects: {
    *init({ payload }, { put, call, select }) {
      yield put({ type: 'getKpiCount' });
      yield put({ type: 'getKpiMoney' });
      yield put({ type: 'getKpiIncrement' });
      yield put({ type: 'getStaticCount' });
      yield put({ type: 'getUnDoList' });

      yield put({ type: 'notification' });
      yield put({ type: 'getLawList' });
      yield put({ type: 'getExcelList' });
    },
    // 年度项目数量KPI完成情况
    *getKpiCount({ payload }, { put, call, select }) {
      const kpiCount = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/index/v1/statistics/kpi/count',
        },
      });
      console.log('请求成功', kpiCount);
      yield put({
        type: 'save',
        payload: {
          kpiCount,
        },
      });
    },
    // 年度项目投资KPI完成情况
    *getKpiMoney({ payload }, { put, call, select }) {
      const kpiMoney = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/index/v1/statistics/kpi/money',
        },
      });
      console.log('请求成功', kpiMoney);
      yield put({
        type: 'save',
        payload: {
          kpiMoney,
        },
      });
    },
    // 年度项目投资KPI完成情况
    *getKpiIncrement({ payload }, { put, call, select }) {
      const KpiIncrement = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/index/v1/statistics/kpi/increment',
        },
      });
      console.log('KpiIncrement', KpiIncrement);
      yield put({
        type: 'save',
        payload: {
          KpiIncrement,
        },
      });
    },

    // 顶部5个数据
    *getStaticCount({ payload }, { put, call, select }) {
      const staticCount = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/index/v1/statistics/count',
        },
      });
      console.log('请求成功', staticCount);
      yield put({
        type: 'save',
        payload: {
          staticCount,
        },
      });
    },
    *getUnDoList({ payload }, { put, call, select }) {
      const res = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/index/v1/pending/query',
          data: { page: 0, size: 20 },
        },
      });
      console.log('请求成功', res);
      yield put({
        type: 'save',
        payload: {
          unDoList: res,
        },
      });
    },

    *notification({ payload }, { put, call, select }) {
      const res = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/article/v1/notification/query',
          data: {
            page: 0,
            size: 10,
            year: new Date().getFullYear(),
          },
        },
      });
      console.log('请求成功', res);
      yield put({
        type: 'save',
        payload: {
          notification: res.dataList,
        },
      });
    },
    *getLawList({ payload }, { put, call, select }) {
      const res = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/article/v1/law/query',
          data: {
            page: 0,
            size: 10,
            year: new Date().getFullYear(),
          },
        },
      });
      console.log('请求成功', res);
      yield put({
        type: 'save',
        payload: {
          lawList: res.dataList,
        },
      });
    },
    *getExcelList({ payload }, { put, call, select }) {
      const res = yield put.resolve({
        type: '$request/post',
        payload: {
          url: '/api/article/v1/table/query',
          data: {
            page: 0,
            size: 10,
          },
        },
      });
      console.log('请求成功', res);
      yield put({
        type: 'save',
        payload: {
          excelList: res.dataList,
        },
      });
    },
  },
};
